package net.tsz.afinal.download;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;
import com.example.aymutilused2.R;

import java.io.File;
import java.io.Serializable;

/**
 * Created by Administrator on 2015/7/4 0004.
 */
public class MyDownLoadQueue implements Serializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private int iconResId;
	private String name;
	private long downSize = 0L;
	private long offSize = 1L;
	private boolean isCancel = false;
	private String downLoadUrl;
	private String downLoadedPath;
	private String fileName;
	private String openFileType;
	private boolean downLoadedAutoOpenFile;

	public MyDownLoadQueue() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getIconResId() {
		return this.iconResId;
	}

	public void setIconResId(int iconResId) {
		this.iconResId = iconResId;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getDownSize() {
		return this.downSize;
	}

	void setDownSize(long downSize) {
		this.downSize = downSize;
	}

	public long getOffSize() {
		return this.offSize;
	}

	void setOffSize(long offSize) {
		this.offSize = offSize;
	}

	public boolean isCancel() {
		return this.isCancel;
	}

	public void setCancel(boolean isCancel) {
		this.isCancel = isCancel;
	}

	public boolean isDownLoadOK() {
		return this.downSize == this.offSize;
	}

	public String getDownLoadUrl() {
		return this.downLoadUrl;
	}

	public void setDownLoadUrl(String downLoadUrl) {
		this.downLoadUrl = downLoadUrl;
	}

	public String getDownLoadedPath() {
		return this.downLoadedPath;
	}

	public void setDownLoadedPath(String downLoadedPath) {
		this.downLoadedPath = downLoadedPath;
	}

	public String getFileName() {
		return this.fileName;
	}

	void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getOpenFileType() {
		return this.openFileType;
	}

	public void setOpenFileType(String openFileType) {
		this.openFileType = openFileType;
	}

	boolean isDownLoadedAutoopenFile() {
		return this.downLoadedAutoOpenFile;
	}

	public void setDownLoadedAutoOpenFile(boolean downLoadedAutoOpenFile, String openFileType) {
		this.downLoadedAutoOpenFile = downLoadedAutoOpenFile;
		this.setOpenFileType(openFileType);
	}

	public void OpenFile(Context context) {
		if(this.isDownLoadOK()) {
			if(this.openFileType != null && !"".equals(this.openFileType)) {
				try {
					Intent e = new Intent("android.intent.action.VIEW");
					Uri name = Uri.fromFile(new File(this.fileName));
					e.setDataAndType(name, this.openFileType);
					e.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					context.startActivity(e);
				} catch (Exception var5) {
					var5.printStackTrace();

					try {
						Toast.makeText(context, R.string.text_openFlie_error, Toast.LENGTH_LONG).show();
					} catch (Exception var4) {
						;
					}
				}

			}
		}
	}
}
